<?php
namespace Mobile\Controller;
class FapiaoController extends BaseController {
    public $fapiaoModel;
    public function __construct() {
        parent::__construct();
        $this->fapiaoModel = M('fapiao');
    }
    
    public function index () {
        $seo = array(
            'title' => '发票申请'
        );
        $this->setSeo($seo);
        if(IS_AJAX) {
            $allow = array(
                'money','head','tax_id','type','province','city','county','address','realname','mobile'
            );
            $data = param_filter($_POST, $allow,$allow,false,true);
            if(empty($data)) {
                return_json(1,'请填写完整');
            }
            $data['uid'] = $this->uid;
            $this->fapiaoModel->add($data);
            return_json(0,'提交成功','','/mobile/fapiao/index');
        }
        $this->display();
    }
    
    public function getFapiao () {
        $where = array(
            'uid' => $this->uid
        );
        $page = get('p',1);
        $size = 10;
        $list = $this->fapiaoModel->where($where)->order('id desc')->page($page,$size)->select();
        $all = $this->fapiaoModel->where($where)->sum('money');
        return_json(0,'success',array(
            'all' => $all>0?$all:0,
            'list' => $list
        ));
    }
}